package com.example.config;

import com.example.domain.Result;
import org.springframework.mail.MailSendException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisDataException;

import java.sql.SQLException;

//作为springmvc的异常处理器
//@ControllerAdvice
@RestControllerAdvice
public class ProjectExceptionAdvice {
    //拦截异常信息
    @ExceptionHandler(SQLException.class)
    public Result sqlException(SQLException ex){
        //记录日志
        //通知运维
        //通知开发
        ex.printStackTrace();
        return new Result(false,"注册失败，已存在该账号！");
    }

    @ExceptionHandler(MailSendException.class)
    public Result mailException(MailSendException ex){
        //记录日志
        //通知运维
        //通知开发
        ex.printStackTrace();
        return new Result(false,"不存在该邮箱地址，其选择正确的邮箱地址注册！");
    }

    @ExceptionHandler(JedisConnectionException.class)
    public Result jesconException(JedisConnectionException ex){
        //记录日志
        //通知运维
        //通知开发
        ex.printStackTrace();
        return new Result(false,"服务器故障，其稍后再试!");
    }

    @ExceptionHandler(JedisDataException.class)
    public Result jesdataException(JedisDataException ex){
        //记录日志
        //通知运维
        //通知开发
        ex.printStackTrace();
        return new Result(false,"服务器故障，其稍后再试!");
    }
}
